package com.zhj.designpatten;

import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.SmartApplicationListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

@Component
public class WechatListener implements SmartApplicationListener {

    @Override
    public boolean supportsEventType(Class<? extends ApplicationEvent> eventType) {
        return eventType == OrderCreateEvent.class;
    }

    @Override
    public boolean supportsSourceType(Class<?> sourceType) {
        return OrderServiceImpl.class == sourceType;
    }

    @Override
    public int getOrder() {
        return 1;
    }

    @Override
    @Async
    public void onApplicationEvent(ApplicationEvent event) {

        OrderCreateEvent event1 = (OrderCreateEvent) event;
        //发送微信
        System.out.println(event1.getContentList().get(0) + ",您的订单:" + event1.getContentList().get(1) + "创建成功! ----by wechat");


    }

    /*@Override
    @Async
    public void onApplicationEvent(OrderCreateEvent event) {
        //发送微信
        System.out.println(event.getContentList().get(0) + ",您的订单:" + event.getContentList().get(1) + "创建成功! ----by wechat");

    }*/

}
